package com.xayy.mgt.controller;

import cn.kawins.base.result.CheckResult;
import cn.kawins.base.result.ResultBody;
import com.xayy.mgt.model.dto.PageDto;
import com.xayy.mgt.model.xinwangmodel.AssessHistory;
import com.xayy.mgt.service.AssessHistoryService;
import com.xayy.mgt.service.OutInterfaceService;
import com.xayy.mgt.service.impl.OutInterfaceServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 对外接口
 * @author plq
 */
@Api(tags = "对外接口")
@RestController
@RequestMapping(value = "/outInterface1")
@Slf4j
public class OutInterfaceController {

    @Autowired
    private OutInterfaceService outInterfaceService;

    @Autowired
    private AssessHistoryService assessHistoryService;

    @GetMapping(value = "/getSatelliteHealth")
    @ApiOperation(value = "获取卫星健康状态",httpMethod = "GET",response = String.class,notes = "对外接口-获取卫星健康状态")
    public ResultBody getSatelliteHealth(
            @ApiParam("评估时间，比如：2023-11-01 00:01:00") @RequestParam("time") Date time,
            @ApiParam("卫星编号，比如：polar 101") @RequestParam("satelliteCode") String satelliteCode,
            @ApiParam("器部件编号，比如：MGQ") @RequestParam(value = "componentCode",required = false) String componentCode
    ) {
        CheckResult<Object> result = outInterfaceService.generateAssessData(satelliteCode,componentCode,time);
        return ResultBody.success(result);
    }

    @GetMapping(value = "/getSatelliteHealthFlow")
    @ApiOperation(value = "获取卫星健康评估状态流程",httpMethod = "GET",response = String.class,notes = "对外接口-获取卫星健康评估状态流程")
    public ResultBody getSatelliteHealthFlow(
            @ApiParam("卫星编号，比如：polar 101") @RequestParam("satelliteCode") String satelliteCode,
            @ApiParam("器部件编号，比如：MGQ") @RequestParam(value = "componentCode",required = false) String componentCode,
            @ApiParam("评估时间，比如：2023-11-01 00:01:00") @RequestParam("time") Date time
    ) {
        CheckResult<Object> result = outInterfaceService.getSatelliteHealthFlow(satelliteCode,time,componentCode);
        return ResultBody.success(result).putExtra("logs",OutInterfaceServiceImpl.HealthFlowLogs);
    }

    @GetMapping(value = "/getBayesAssessFlow")
    @ApiOperation(value = "获取贝叶斯评估状态流程（采样评估）",httpMethod = "GET",response = String.class,notes = "对外接口-获取贝叶斯评估状态流程（采样评估）")
    public ResultBody getBayesAssessFlow(
            @ApiParam("器部件编号:比如：DLL") @RequestParam(value = "componentCode",required = false) String componentCode,
            @ApiParam("故障采样率:10,9,8,7,6,5,4,3,2,1 分别表示 10%,20%,30% .... 100% ") @RequestParam("errorSampling") int errorSampling,
            @ApiParam("正常采样率:10,9,8,7,6,5,4,3,2,1 分别表示 10%,20%,30% .... 100% ") @RequestParam("sampling") int sampling,
            @ApiParam("评估时间，比如：2023-10-01 00:02:00") @RequestParam("time") Date time
    ) {
        CheckResult<Object> result = outInterfaceService.getBayesAssessFlow(componentCode,errorSampling,sampling,time);
        return ResultBody.success(result).putExtra("logs",OutInterfaceServiceImpl.bayesFlowLogs);
    }

    @GetMapping(value = "/getConstellationFlow")
    @ApiOperation(value = "获取星座物理拓扑评估状态流程",httpMethod = "GET",response = String.class,notes = "对外接口-获取星座物理拓扑评估状态流程")
    public ResultBody getConstellationFlow(
            @ApiParam("算法类型:0-权重分析法，1-神经网络") @RequestParam("algorithmType") int algorithmType,
            @ApiParam("星座名称: 比如：极轨星座（60）") @RequestParam("constellationName") String constellationName,
            @ApiParam("评估时间: 比如：2023-11-12 00:02:00") @RequestParam("time") Date time
    ) {
        CheckResult<Object> result = outInterfaceService.getConstellationFlow(algorithmType,constellationName,time);
        return ResultBody.success(result).putExtra("logs",OutInterfaceServiceImpl.xzFlowLogs);
    }

    @PostMapping(value = "/getAssessHistory")
    @ApiOperation(value = "获取星座物理拓扑评估历史分页",httpMethod = "POST",response = AssessHistory.class,notes = "对外接口-获取星座物理拓扑评估历史分页")
    public ResultBody getAssessHistory(@RequestBody PageDto pageDto) {
        return assessHistoryService.getAssessHistory(pageDto).body();
    }

}
